package com.ejoysoft.wlanyz.business; 

import com.ejoysoft.common.DbConnect;
import com.ejoysoft.common.Globa;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;


public class Ac {

    private Globa globa;
    private DbConnect db;

    //构造方法
    public Ac() {
    }

    public Ac(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    //构造方法 
    public Ac(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }
   
    //详细显示单条记录
    public Ac show(String where) throws SQLException{
        try {
            String strSql = "select * from  " + strTableName + "  ".concat(String.valueOf (where ));
            ResultSet rs = db.executeQuery(strSql);
            if (rs != null && rs.next())
                return load(rs);
            else
                return null;
        } catch (Exception ee) {
            return null;
        }
    }

    //记录集转化为对象
    public Ac load(ResultSet rs) throws SQLException{
    	Ac theBean = new Ac();
        try {
            theBean.setStrId(rs.getString("strId"));
            theBean.setClassOneAC(rs.getString("classOneAC"));
            theBean.setClassTwoAC(rs.getString("classTwoAC"));
            theBean.setStrCity(rs.getString("strCity"));
            theBean.setStrCountry(rs.getString("strCountry"));
            theBean.setStrType(rs.getString("strType"));
            theBean.setStrCreator(rs.getString("strCreator"));
            theBean.setDtCreatTime(rs.getString("dtCreateTime"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return theBean;
    }

    //查询符合条件的记录�?�数
    public int getCount(String where) throws SQLException{
        int count = 0;
        try {
            String sql = "SELECT count(*) FROM " + strTableName + "  ";
            if (where.length() > 0) {
                where = where.toLowerCase();
                if (where.indexOf("order") > 0)
                    where = where.substring(0, where.indexOf("order"));
                sql = String.valueOf(sql) + String.valueOf(where);
            }
            ResultSet rs = db.executeQuery(sql);
            if (rs.next())
                count = rs.getInt(1);
            rs.close();
            return count;
        } catch (Exception ee) {
            ee.printStackTrace();
            return count;
        }
    }
   

    //列表记录
    public Vector<Ac> list(String where, int startRow, int rowCount) throws SQLException{
        Vector<Ac> beans = new Vector<Ac>();
        try {
            String sql = "SELECT *  FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                    Ac theBean = new Ac();
                    theBean = load(rs);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return beans;
    } 

    //列表记录
    public Vector<Ac> listClassTwoAcs(String where){
    	db = new DbConnect();
        Vector<Ac> beans = new Vector<Ac>();
        try {
            String sql = "SELECT * FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
             ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next()) {
                do {
                    Ac theBean = new Ac();
                    theBean.setClassTwoAC(rs.getString("classTwoAC"));
                    theBean.setStrId(rs.getString("strId"));
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
        return beans;
    } 
    
    //获取所有城市 
    public ArrayList<String> listAllCitys(String where)
    {
    	db = new DbConnect();
    	ArrayList<String> beans = new ArrayList<String>();
        try {
            String sql = "SELECT distinct(strCity) FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
             ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next()) {
                do {
                    beans.add(rs.getString("strCity")); 
                } while (rs.next());
            }
            rs.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
    	return beans;
    }
  //获取某城市的所有区县
    public ArrayList<String> listCountriesOfCity(String where)
    {
    	db = new DbConnect();
    	ArrayList<String> beans = new ArrayList<String>();
        try {
            String sql = "SELECT distinct(strCountry) FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
             ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next()) {
                do {
                    beans.add(rs.getString("strCountry")); 
                } while (rs.next());
            }
            rs.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
    	return beans;
    }
    
    //获取某城市的所有区县
    public ArrayList<String> listClassOneAcs(String where)
    {
    	db = new DbConnect();
    	ArrayList<String> beans = new ArrayList<String>();
        try {
            String sql = "SELECT distinct(classOneAC) FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
             ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next()) {
                do {
                    beans.add(rs.getString("classOneAC"));
                } while (rs.next());
            }
            rs.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
    	return beans;
    }
    //列表记录
    public Vector<Ac> listClassOneAcs1(String where){
    	db = new DbConnect();
        Vector<Ac> beans = new Vector<Ac>();
        try {
            String sql = "SELECT * FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
             ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next()) {
                do {
                    Ac theBean = new Ac();
                    theBean.setClassOneAC(rs.getString("classOneAC"));
                    theBean.setStrId(rs.getString("strId"));
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        db.closeCon();
        return beans;
    } 
   
    private String strTableName = "ac_class_associate";
    private String strId;  //	记录ID
    private String classOneAC;  //一级热点名称
    private String classTwoAC;  //二级热点名称
    private String strType;  //		AC类型
    private String dtCreatTime;  //		创建时间
    private String strCity;//热点城市
    private String strCountry;//热点区县
    private String strCreator;//创建人

	public Globa getGloba() {
		return globa;
	}

	public void setGloba(Globa globa) {
		this.globa = globa;
	}

	public DbConnect getDb() {
		return db;
	}

	public void setDb(DbConnect db) {
		this.db = db;
	}

	public String getStrId() {
		return strId;
	}

	public void setStrId(String strId) {
		this.strId = strId;
	}

	public String getClassOneAC() {
		return classOneAC;
	}

	public void setClassOneAC(String classOneAC) {
		this.classOneAC = classOneAC;
	}

	public String getClassTwoAC() {
		return classTwoAC;
	}

	public void setClassTwoAC(String classTwoAC) {
		this.classTwoAC = classTwoAC;
	}

	public String getStrType() {
		return strType;
	}

	public void setStrType(String strType) {
		this.strType = strType;
	}

	public String getDtCreatTime() {
		return dtCreatTime;
	}

	public void setDtCreatTime(String dtCreatTime) {
		this.dtCreatTime = dtCreatTime;
	}

	public String getStrCity() {
		return strCity;
	}

	public void setStrCity(String strCity) {
		this.strCity = strCity;
	}

	public String getStrCountry() {
		return strCountry;
	}

	public void setStrCountry(String strCountry) {
		this.strCountry = strCountry;
	}

	public String getStrCreator() {
		return strCreator;
	}

	public void setStrCreator(String strCreator) {
		this.strCreator = strCreator;
	}
    
}